<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-02 13:13:25
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2024-01-04 10:42:12
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <div class="defaultboxYJ">
        <div class="app-container-btn">
          <el-button
            type="primary"
            v-if="btnShow"
            @click="yj_saveForm(formData)"
            >保存</el-button
          >

          <el-button @click="goBack">返回</el-button>
        </div>
        <!-- 表格 -->
        <div class="text_table TensionRealTime">
          <div class="dialogBody common table_detail yjxa_detail">
            <!-- <div class="app-container-area-title">
                <span class="app-container-area-title-divider"></span>
                <span>基本信息</span>
              </div> -->

            <publicForm
              ref="publicForm"
              lableWidth="160px"
              :formObj="formObj"
              :formData="formData"
              @selectChange="selectChange"
              @inputFocus="inputFocus"
            >
            </publicForm>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
    
<script>
import actions from "@/actions";
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getTensioningTaskByfId, //详情接口
  saveTensioningTask, //编辑保存
  getTensioningTaskNo, //新增任务单号
  getStationmachineList, //梁场
  getMachineListByStationId, //4张拉   5压浆
} from "@/api/request.js";

export default {
  name: "Tension_task_list_details",
  data() {
    return {
      name: "Tension_task_list_details", //按钮配置页面代号
      btnShow: true,
      formObj: formJs.formStateText,
      formObjText: formJs.formStateText,
      formObjLook: formJs.formState,
      formData: {
        fId: "", //id
        fCompanyid: "", //标段id
        fCompanyname: "", //标段名称
        fProjectid: "", //项目id
        fProjectname: "", //项目名称
        fTaskno: "", //任务单号
        fBeamid: "", //梁场编号
        fBeamname: "", //梁场名称
        fMachineid: "", //设备编号
        fMachinename: "", //设备名称
        fWbsid: "", //工程部位id
        fWbsname: "", //工程部位
        fConcretedesignstrength: "", //混凝土设计强度(张拉) / 孔道类型(压浆)
        fPlantensioningdates: "", //计划张拉日期
        fTensioningforce: "", //设计张拉力
        fBeamtype: "", //梁型
        fBeamnumber: "", //梁号
        fPouringdates: "", //浇筑日期
        fBeamrealname: "", //梁名称
        fAge: "", //龄期
        fProcessnum: "", //孔道数
        fDesigndensity: "", //设计密度(压浆)
        fTheoreticalslurry: "", //理论浆量(压浆)
        fTaskuserid: "", //提交人id
        fTaskusername: "", //提交人
        fTaskdates: "", //创建时间
        fStatus: "未完成", //状态
        fNote: "1", //1 张拉 2压浆
      }, //数据
      userInfo: {}, //登录用户
      timeYMD: null, //当前时间  年月日
      timeYmdHms: null, //当前时间  年月日时分秒
      Taskno: null, //新增任务单号
      bhzDataList: [], //梁场
      bhjDataList: [], //张拉机
      projectsObj: [], //项目名
      tendersObj: [], //标段
      token: null,
    };
  },
  components: {
    publicForm, //弹框表格
  },

  created() {},
  mounted() {
    this.formObj = this.formObjText;
    this.getData();
    actions.onGlobalStateChange((state, prev) => {
      this.projectsObj = prev.currentUser.projects;
      this.token = prev.token;
      this.userInfo = prev.currentUser;
      // console.log("用户", this.userInfo);
      var projectsArr = [];
      this.projectsObj.map((item) => {
        projectsArr.push({
          label: item.projectName,
          value: item.projectId,
        });
      });
      this.formObjText[0].options = projectsArr;
    }, true);

    if (JSON.parse(sessionStorage.getItem("GxEmbedded_TWbsQuery"))) {
      var dataList = JSON.parse(sessionStorage.getItem("GxEmbedded_TWbsQuery"));
      this.btnShow = true;
      if (dataList.num == "编辑") {
        this.yj_viewForm(dataList);
      } else if (dataList.num == "查看") {
        this.formObj = this.formObjLook;
        this.yj_viewForm(dataList);
        this.btnShow = false;
      } else if (dataList.num == "新增") {
        // console.log(dataList.num);
        this.formData = {
          fId: "", //id
          fCompanyid: "", //标段id
          fCompanyname: "", //标段名称
          fProjectid: "", //项目id
          fProjectname: "", //项目名称
          fTaskno: "", //任务单号
          fBeamid: "", //梁场编号
          fBeamname: "", //梁场名称
          fBeamrealname: "", //梁名称
          fAge: "", //龄期
          fMachineid: "", //设备编号
          fMachinename: "", //设备名称
          fWbsid: "", //工程部位id
          fWbsname: "", //工程部位
          fConcretedesignstrength: "", //混凝土设计强度(张拉) / 孔道类型(压浆)
          fPlantensioningdates: "", //计划张拉日期
          fTensioningforce: "", //设计张拉力
          fBeamtype: "", //梁型
          fBeamnumber: "", //梁号
          fPouringdates: "", //浇筑日期
          fProcessnum: "", //孔道数
          fDesigndensity: "", //设计密度(压浆)
          fTheoreticalslurry: "", //理论浆量(压浆)
          fTaskuserid: this.userInfo.id, //创建人id
          fTaskusername: this.userInfo.userName, //创建人
          fTaskdates: this.timeYmdHms, //创建时间
          fStatus: "未完成", //状态
          fNote: "1", //1 张拉 2压浆
        };
        this.formObjText[1].options = [];
        this.formObjText[2].options = [];
        this.formObjText[3].options = [];
        this.formObjText[5].disabled = true;
      } else {
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_TensionDetaFrom"))) {
          var NewDataFrom = JSON.parse(
            sessionStorage.getItem("GxEmbedded_TensionDetaFrom")
          );
          if (
            JSON.parse(sessionStorage.getItem("GxEmbedded_Tension_Wbs_Deta"))
          ) {
            var WbsList = JSON.parse(
              sessionStorage.getItem("GxEmbedded_Tension_Wbs_Deta")
            );
            this.formData = NewDataFrom;
            if (WbsList.fLongname != "" && WbsList.fLongname != null) {
              this.formData.fWbsname = WbsList.fLongname;
            } else {
              this.formData.fWbsname = WbsList.fName;
            }
            this.formData.fWbsid = WbsList.fNodeid;
          } else {
            this.formData = NewDataFrom;
          }

          if (NewDataFrom.fProjectid != "") {
            this.getTender(NewDataFrom.fProjectid);
          }
          if (NewDataFrom.fCompanyid != "") {
            this.mixingPlantList(0, NewDataFrom.fCompanyid);
          }
          if (NewDataFrom.fBeamid != "") {
            this.getbhjDataMethods(NewDataFrom.fBeamid, 4);
          }
        }
      }
    }

    // this.btnRole(this.name);
  },

  methods: {
    goBack() {
      this.$router.push({
        path: "/tensionManage/tensionTaskList",
      });
      window.sessionStorage.removeItem("GxEmbedded_TWbsQuery");
      window.sessionStorage.removeItem("GxEmbedded_TensionDetaFrom");
      window.sessionStorage.removeItem("GxEmbedded_Tension_Wbs_Deta");
    },
    // btnRole(name) {
    //   // 按钮权限
    //   var btnList = [];
    //   var ModuleList = JSON.parse(sessionStorage.getItem("GxEmbedded_ModuleList"));
    //   if (ModuleList.length > 0) {
    //     ModuleList.map((item) => {
    //       if (item.fEncode == name) {
    //         btnList = item.modulebuttonList;
    //       }
    //     });
    //     var btnStr = [];
    //     btnList.map((item) => {
    //       btnStr.push(item.fEncode);
    //     });
    //     // this.yj_view = btnStr.includes("yj_view");
    //   } else {
    //     // this.yj_view = true;
    //   }
    // },
    // 任务单号
    TaskNoFun(id) {
      var data = {
        fCompanyid: id, //标段id
        keyType: "1", ////张拉 1 压浆 2 必填
      };
      getTensioningTaskNo(data)
        .then((res) => {
          if (res.errcode == 0) {
            this.Taskno = res.data.yjQmpMsTensioningtask.fTaskno;
            this.formData.fTaskno = this.Taskno;
          } else {
            this.$MessageBox.alertConfirmReminder(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 标段列表
    async getTender(e) {
      await this.$http(
        " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
          e,
        {
          headers: {
            "Content-Type": "application/json",
            Authorization: localStorage.getItem("access_token"),
          },
        }
      ).then((res) => {
        if (res.status == 200) {
          this.tendersObj = res.data.data.GXCompanyList;
          var tendersArr = [];

          this.tendersObj.map((item) => {
            tendersArr.push({
              label: item.sectionName,
              value: item.sectionId,
            });
          });
          this.formObjText[1].options = tendersArr;
        }
      });
    },

    // 查看
    yj_viewForm(obj) {
      this.formData = this.$options.data.call(this).formData;
      var data = {
        fCompanyid: obj.fCompanyid, //标段id
        fId: obj.fId, //数据id
      };
      getTensioningTaskByfId(data)
        .then((res) => {
          if (res.errcode == 0) {
            // this.listLoading = false;
            this.formData = res.data.yjQmpMsTensioningtask;

            if (
              JSON.parse(sessionStorage.getItem("GxEmbedded_TWbsQuery")).num ==
              "编辑"
            ) {
              if (
                this.formData.fTaskusername == "" ||
                this.formData.fTaskusername == null
              ) {
                this.formData.fTaskuserid = this.userInfo.id; //创建人id
                this.formData.fTaskusername = this.userInfo.userName; //创建人姓名
              }
              if (
                this.formData.fTaskdates == "" ||
                this.formData.fTaskdates == null
              ) {
                this.formData.fTaskdates = this.timeYmdHms; //创建时间
              }
              if (
                this.formData.fTaskno == "" ||
                this.formData.fTaskno == null
              ) {
                this.formData.fTaskno = this.Taskno; //任务单号
              }

              if (
                this.formData.fCompanyname == "" ||
                this.formData.fCompanyname == null
              ) {
                this.formObjText[5].disabled = true;
              } else {
                this.formObjText[5].disabled = false;
              }

              if (
                JSON.parse(sessionStorage.getItem("GxEmbedded_TensionDetaFrom"))
              ) {
                if (
                  JSON.parse(
                    sessionStorage.getItem("GxEmbedded_Tension_Wbs_Deta")
                  )
                ) {
                  var WbsList = JSON.parse(
                    sessionStorage.getItem("GxEmbedded_Tension_Wbs_Deta")
                  );

                  this.formData = JSON.parse(
                    sessionStorage.getItem("GxEmbedded_TensionDetaFrom")
                  );

                  if (WbsList.fLongname != "" && WbsList.fLongname != null) {
                    this.formData.fWbsname = WbsList.fLongname;
                  } else {
                    this.formData.fWbsname = WbsList.fName;
                  }
                  this.formData.fWbsid = WbsList.fNodeid;
                } else {
                  this.formData = JSON.parse(
                    sessionStorage.getItem("GxEmbedded_TensionDetaFrom")
                  );
                }
              }

              if (this.formData.fProjectid != "") {
                this.getTender(this.formData.fProjectid);
              }
              if (this.formData.fCompanyid != "") {
                this.mixingPlantList(0, this.formData.fCompanyid);
              }
              if (this.formData.fBeamid != "") {
                this.getbhjDataMethods(this.formData.fBeamid, 4);
              }
            }
          } else {
            this.$MessageBox.alertConfirmReminder(res.msg);

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 保存接口
    yj_saveForm(data) {
      if (this.$refs.publicForm.submitForm()) {
        var saveData = {
          fId: data.fId, //id
          fCompanyid: data.fCompanyid, //标段id
          fCompanyname: data.fCompanyname, //标段名称
          fProjectid: data.fProjectid, //项目id
          fProjectname: data.fProjectname, //项目名称
          fTaskno: data.fTaskno, //任务单号
          fBeamid: data.fBeamid, //梁场编号
          fBeamname: data.fBeamname, //梁场名称
          fMachineid: data.fMachineid, //设备编号
          fMachinename: data.fMachinename, //设备名称
          fBeamrealname: data.fBeamrealname, //梁名称
          fAge: data.fAge, //龄期
          fPouringdates: data.fPouringdates, //浇筑日期
          fWbsid: data.fWbsid, //工程部位id
          fWbsname: data.fWbsname, //工程部位
          fConcretedesignstrength: data.fConcretedesignstrength, //混凝土设计强度(张拉) / 孔道类型(压浆)
          fPlantensioningdates: data.fPlantensioningdates, //计划张拉日期
          fTensioningforce: data.fTensioningforce, //设计张拉力
          fBeamtype: data.fBeamtype, //梁型
          fBeamnumber: data.fBeamnumber, //梁号
          fProcessnum: data.fProcessnum, //孔道数
          fDesigndensity: data.fDesigndensity, //设计密度(压浆)
          fTheoreticalslurry: data.fTheoreticalslurry, //理论浆量(压浆)
          fTaskuserid: data.fTaskuserid, //创建人id
          fTaskusername: data.fTaskusername, //创建人
          fTaskdates: data.fTaskdates, //创建时间
          fStatus: data.fStatus, //状态
          fNote: "1", //1 张拉 2压浆
          userId: this.userInfo.id, //提交人id
          userName: this.userInfo.userName, //提交人
        };

        saveTensioningTask(saveData)
          .then((res) => {
            if (res.errcode == 0) {
              this.$router.push("/tensionManage/tensionTaskList");
              this.$message.success("保存成功");
              window.sessionStorage.removeItem("GxEmbedded_TWbsQuery");
              window.sessionStorage.removeItem("GxEmbedded_TensionDetaFrom");
              window.sessionStorage.removeItem("GxEmbedded_Tension_Wbs_Deta");
            } else {
              this.$message.error(res.msg);
              console.log("接口报错");
            }
          })
          .catch((error) => {
            console.log("任务单保存接口报错", error);
          });
      } else {
        console.log("error");
        // this.$MessageBox.alertConfirmReminder("请把信息填写完整");
        // return false;
      }
    },
    // 获取时间
    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      const hh = (time.getHours() + "").padStart(2, "0");
      const mm = (time.getMinutes() + "").padStart(2, "0");
      const ss = (time.getSeconds() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
      this.timeYmdHms = `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    },
    // 获取梁场
    mixingPlantList(num, id) {
      var data = {
        companyId: id, // 施工标段id
        modelType: num, // 类型
        stationType: "4", // 拌合站类型
      };
      this.bhzDataList = [];
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            arr.map((item) => {
              this.bhzDataList.push({
                label: item.fMachinename,
                value: item.fMachineid,
              });
            });

            this.formObjText[2].options = this.bhzDataList;
          } else {
            // this.$message.error(res.msg);
            this.$MessageBox.alertConfirmReminder(res.msg);

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 张拉机
    getbhjDataMethods(data, num) {
      this.bhjDataList = [];
      getMachineListByStationId({ stationId: data, modelType: num })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            arr.map((item) => {
              this.bhjDataList.push({
                label: item.fMachinename,
                value: item.fMachineid,
              });
            });
            this.formObjText[3].options = this.bhjDataList;
          } else {
            // this.$message.error(res.msg);
            this.$MessageBox.alertConfirmReminder(res.msg);

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    selectChange(value, index, prop) {
      console.log("selectChange", value, index, prop);
      if (prop == "fProjectname") {
        this.formData.fCompanyname = "";
        this.formData.fCompanyid = "";
        this.formData.fBeamname = "";
        this.formData.fBeamid = "";
        this.formData.fMachinename = "";
        this.formData.fMachineid = "";

        this.formObjText[1].options = [];
        this.formObjText[2].options = [];
        this.formObjText[3].options = [];
        this.formObjText[5].disabled = true;
        this.projectsObj.map((item) => {
          if (value == item.projectName) {
            this.formData.fProjectid = item.projectId;
            this.getTender(item.projectId);
          }
        });
      }

      if (prop == "fCompanyname" ) {
        window.sessionStorage.removeItem("GxEmbedded_Tension_Wbs_Deta");

        this.formData.fBeamname = "";
        this.formData.fBeamid = "";
        this.formData.fMachinename = "";
        this.formData.fMachineid = "";
        this.formData.fWbsname = ""; //工程名
        this.formData.fWbsid = ""; //工程id

        this.formObjText[2].options = [];
        this.formObjText[3].options = [];
        this.formObjText[5].disabled = false;

        this.tendersObj.map((item) => {
          if (value == item.sectionName) {
            this.formData.fCompanyid = item.sectionId;
            this.mixingPlantList(0, this.formData.fCompanyid);
            if (
              JSON.parse(sessionStorage.getItem("GxEmbedded_TWbsQuery")).num ==
              "新增"
            ) {
              this.TaskNoFun(this.formData.fCompanyid);
            }
          }
        });
      }

      if (prop == "fBeamname") {
        this.formData.fMachinename = "";
        this.formData.fMachineid = "";
        // console.log(88, this.bhzDataList);
        this.bhzDataList.map((item) => {
          if (item.label == value) {
            this.formData.fBeamid = item.value;
            this.getbhjDataMethods(this.formData.fBeamid, 4);
          }
        });
      }

      if (prop == "fMachinename") {
        this.bhjDataList.map((item) => {
          if (item.label == value) {
            this.formData.fMachineid = item.value;
          }
        });
      }

      setTimeout(() => {
        window.sessionStorage.setItem(
          "GxEmbedded_TensionDetaFrom",
          JSON.stringify(this.formData)
        );
      }, 500);
    },
    inputFocus(index, prop) {
      // console.log(index, prop);
      if (index == "5" && prop == "fWbsname") {
        this.$router.push({
          path: "/tensionManage/tensionTaskListTree",
          query: {
            secId: this.formData,
            text: "张拉-任务单下发",
          },
        });
      }

      setTimeout(() => {
        window.sessionStorage.setItem(
          "GxEmbedded_TensionDetaFrom",
          JSON.stringify(this.formData)
        );
      }, 500);
    },
  },
};
</script>
    
<style scoped lang='less'>
.defaultboxYJ {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.TensionRealTime {
  // flex: 1;
  height: 100%;

  // height: calc(100% - 200px);
  display: flex;
  flex-direction: column;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.TensionAndGrout_dialog .dialogBody {
  padding: 3px 20px;
  height: 98% !important;
  /* overflow-y: auto; */
}

.dialogBodyBox {
  width: 100%;

  .tab {
    display: flex;
    font-size: 14px;
    height: 30px;
    line-height: 30px;
    box-sizing: border-box;
    border-bottom: 2px solid #e4e7ed;
    padding: 0 0.16rem;

    .btn {
      margin-top: 4px;
      // margin-right: 16px;
      width: 80px;
      height: 24px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-top-right-radius: 4px;
      border-top-left-radius: 4px;
    }
  }

  .charts {
    height: calc(100% - 30px);
  }
}

.mechanism_dialogS /deep/ .el-table__body-wrapper {
  height: calc(100% - 84px);
  overflow-y: auto;
}

.mechanism_dialogS /deep/ .el-table__body-wrapper::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  z-index: 99999999 !important;
}

.common .block {
  bottom: 5px !important;
}
</style>